#include <string>
#include <vector>
#include <iosfwd>

struct DayTime {
    int h;
    int m;
    int s;
    
    auto seconds() const {
        return (h * 3600 + m * 60 + s);
    }

    bool operator<(DayTime const & other) const {
        return this->seconds() < other.seconds();
    }

    bool operator==(DayTime const & other) const {
        return h == other.h && m == other.m && s == other.s;
    }

    bool operator!=(DayTime const & other) const {
        return !(*this == other);
    }

    static auto parse(std::string a) {
        return DayTime {
            std::stoi(a.substr(0, 2)),
            std::stoi(a.substr(3, 2)),
            std::stoi(a.substr(6, 2))
        };
    }

    auto to_string() const {
        std::string strs[3] = {
            std::to_string(h),
            std::to_string(m),
            std::to_string(s)
        };
        for (auto & str : strs) {
            if (str.size() < 2) {
                str.insert(0, "0");
            }
        }
        return strs[0] + ":" + strs[1] + ":" + strs[2];
    }

    friend std::ostream & operator<<(std::ostream & os, DayTime const & time) {
        os << time.to_string();
        return os;
    }
};

#include <iostream>
#include <algorithm>

int main() {
    int n;
    std::cin >> n;

    std::vector<DayTime> timestamps;

    for (int i = 0; i < n; ++i) {
        std::string s;
        std::cin >> s;
        timestamps.push_back(DayTime::parse(s));
        std::cin >> s;
        std::cin >> s;
        timestamps.push_back(DayTime::parse(s));
    }

    std::sort(timestamps.begin(), timestamps.end());
    
    auto i = timestamps.begin();
    
    if (*i != DayTime{0, 0, 0}) {
        std::cout << DayTime{0, 0, 0} << " - " << *i << "\n";
    }

    auto cnt = 2;
    ++i;

    while (i != timestamps.end()) {
        if (cnt % 2 == 1) {
            if (!(*(i-1) == *i )) {
                std::cout << *(i-1) << " - " << *i << "\n";
            }
        }
        cnt += 1;
        ++i;
    }

    if (*(i-1) != DayTime{23, 59, 59}) {
        std::cout << *(i-1) << " - " << DayTime{23, 59, 59} << "\n";
    }
    
}
